/*
 * @Author: szx
 * @Date: 2021-10-31 10:32:12
 * @LastEditTime: 2021-10-31 11:05:17
 * @Description:
 * @FilePath: \leetcode\500-599\500\500.cpp
 */
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
class Solution {
   public:
    vector<string> findWords(vector<string>& words) {
        vector<string> v;
        unordered_set<char> s[3];
        s[0] = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'};
        s[1] = {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'};
        s[2] = {'z', 'x', 'c', 'v', 'b', 'n', 'm'};
        for (string word : words) {
            bool flag = true;
            string l_word = toLowerCase(word);
            int i = 0;
            for (; i < 3; i++) {
                auto it = s[i].find(l_word[0]);
                if (it != s[i].end()) {
                    break;
                }
            }
            for (int j = 1; j < l_word.length(); j++) {
                auto it = s[i].find(l_word[j]);
                if (it == s[i].end()) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                v.push_back(word);
            }
        }
        return v;
    }
    string toLowerCase(string str) {
        for (int i = 0; i < str.size(); i++) {
            if (str[i] >= 'A' && str[i] <= 'Z') {
                str[i] = str[i] - 'A' + 'a';
            }
        }
        return str;
    }
};

using namespace std;
int main() {
    Solution s;
    vector<string> v{"Hello", "Alaska", "Dad", "Peace"};
    vector<string> res = s.findWords(v);
    for (string str : res) {
        cout << str << " ";
    }
    return 0;
}